package com.liwenfeng.thread;

import com.sun.net.httpserver.Headers;
import com.sun.net.httpserver.Request;

import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.BinaryOperator;

public class ThreadTest {
    public static void main(String[] args) {
//        MyThread myThread = new MyThread();
//        myThread.start();
//
//        for (int i = 0; i < 5; i++) {
//            System.out.println(Thread.currentThread().getName()+"===主线程执行了。。。");
//        }

        BaoZiPu baoZiPu = new BaoZiPu();

        Runnable consumerRun = () -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                    baoZiPu.consumer();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };

        Runnable productRun = () -> {
            while (true) {
                try {
                    Thread.sleep(1000);
                    baoZiPu.product();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        };

        new Thread(consumerRun).start();
        new Thread(consumerRun).start();
        new Thread(consumerRun).start();
        new Thread(consumerRun).start();
        new Thread(consumerRun).start();
        new Thread(consumerRun).start();

        new Thread(productRun).start();
        new Thread(productRun).start();
        new Thread(productRun).start();
        new Thread(productRun).start();
        new Thread(productRun).start();
        new Thread(productRun).start();

    }
}
